package com.ruoyi.internship.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.internship.dto.PositionDetailDTO;
import com.ruoyi.internship.vo.PositionList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.internship.domain.BolePosition;
import com.ruoyi.internship.service.IBolePositionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职位信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/internship/position")
public class BolePositionController extends BaseController
{
    @Autowired
    private IBolePositionService bolePositionService;

//详细信息
    @GetMapping("/positionDetail/{positionId}/{companyId}")
    public AjaxResult getPositionDetail(@PathVariable("positionId") String positionId,
                                        @PathVariable("companyId") String companyId)
    {
        PositionDetailDTO positionDetailDTO = bolePositionService.getPositionDetail(Long.parseLong(positionId), Long.parseLong(companyId));
        return success(positionDetailDTO);
    }
//    职位列表
    @GetMapping("/positionList")
    public TableDataInfo BolePositionController(String search,String pageNum,String pageSize)
    {
        startPage();
        List<PositionList> list = bolePositionService.getPostionList(search);
        return getDataTable(list);
    }
    /**
     * 查询职位信息列表
     */
//    @PreAuthorize("@ss.hasPermi('internship:position:list')")
    @GetMapping("/list")
    public TableDataInfo list(BolePosition bolePosition)
    {
        startPage();
        List<BolePosition> list = bolePositionService.selectBolePositionList(bolePosition);
        return getDataTable(list);
    }

    /**
     * 导出职位信息列表
     */
    @PreAuthorize("@ss.hasPermi('internship:position:export')")
    @Log(title = "职位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BolePosition bolePosition)
    {
        List<BolePosition> list = bolePositionService.selectBolePositionList(bolePosition);
        ExcelUtil<BolePosition> util = new ExcelUtil<BolePosition>(BolePosition.class);
        util.exportExcel(response, list, "职位信息数据");
    }

    /**
     * 获取职位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('internship:position:query')")
    @GetMapping(value = "/{positionId}")
    public AjaxResult getInfo(@PathVariable("positionId") String positionId)
    {
        return success(bolePositionService.selectBolePositionByPositionId(positionId));
    }

    /**
     * 新增职位信息
     */
    @PreAuthorize("@ss.hasPermi('internship:position:add')")
    @Log(title = "职位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BolePosition bolePosition)
    {
        bolePosition.setCreateTime(DateUtils.getNowDate());
        bolePosition.setUpdateTime(DateUtils.getNowDate());
        return toAjax(bolePositionService.insertBolePosition(bolePosition));
    }

    /**
     * 修改职位信息
     */
    @PreAuthorize("@ss.hasPermi('internship:position:edit')")
    @Log(title = "职位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BolePosition bolePosition)
    {
        return toAjax(bolePositionService.updateBolePosition(bolePosition));
    }

    /**
     * 删除职位信息
     */
    @PreAuthorize("@ss.hasPermi('internship:position:remove')")
    @Log(title = "职位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{positionIds}")
    public AjaxResult remove(@PathVariable String[] positionIds)
    {
        return toAjax(bolePositionService.deleteBolePositionByPositionIds(positionIds));
    }
}
